package com.tanhua.app.controller;

import com.tanhua.app.Service.CommentsService;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;


//    评论列表
//    GET  /comments
    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       String movementId){
        PageResult pr = commentsService.findComments(movementId,page,pageSize);
        return ResponseEntity.ok(pr);
    }

//    评论提交
//    POST  /comments
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map<String,String> map){
        String movementId = map.get("movementId");
        String comment = map.get("comment");
        commentsService.saveComments(movementId,comment);
        return ResponseEntity.ok(null);
    }

//    评论-点赞
//    GET   /comments/:id/like
    @GetMapping("/{id}/like")
    public ResponseEntity likeComments(@PathVariable("id") String commentId){
        Integer likeCount = commentsService.likeComments(commentId);
        return ResponseEntity.ok(likeCount);
    }

//    评论-取消点赞
//    GET   /comments/:id/dislike
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislikeComments(@PathVariable("id") String commentId){
        Integer likeCount = commentsService.dislikeComments(commentId);
        return ResponseEntity.ok(likeCount);
    }
}
